package com.activiti.basic.util;


import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by beike on 2019/4/22.
 * 系统基础参数定义
 */
public class Status {
    //状态码
    public final static String SUCCESS = "200";
    public final static String FAIL = "500";
    public final static String NO_LOGIN = "401";
    public final static String NO_PRIVILEGE = "403";

    //资源状态
    public final static int DELETE = 0;
    public final static int ENABLE = 1;
    public final static int DISABLE = 2;

    // 发红包算法，金额参数以分为单位
    public static List<Integer> divideRedPackage(Integer totalAmount, Integer totalPeopleNum) {
        List<Integer> amountList = new ArrayList<Integer>();
        Integer restPeopleNum = totalPeopleNum;
        Random random = new Random();
        for (int i = 0; i < totalPeopleNum - 1; i++) {
            // 随机范围：[1，剩余人均金额的两倍)，左闭右开
            int amount = random.nextInt(totalAmount / restPeopleNum * 2 - 1) + 1;
            totalAmount -= amount;
            restPeopleNum--;
            amountList.add(amount);
        }
        amountList.add(totalAmount);
        return amountList;
    }

    public static void main(String[] args) {
        double totalAmount = 5;
        List<Integer> amountList = divideRedPackage((int)(totalAmount * 100), 3);
        for (Integer amount : amountList) {
            System.out.println("抢到金额：" + new BigDecimal(amount).divide(new BigDecimal(100)));
        }
    }
}
